/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.tom.social.watcher.agent;

import jade.core.Agent;
import jade.domain.DFService;
import jade.domain.FIPAException;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import pl.tom.social.watcher.agent.behaviour.AdminBehaviour;
import pl.tom.social.watcher.jade.LocalJade;

/**
 *
 * @author Tom
 */
public class WatcherAdminAgent extends Agent {

	private static final Logger logger = Logger.getLogger(WatcherAdminAgent.class);
	private static WatcherAdminAgent instance = null;

	private WatcherAdminAgent() {
	}

	public static synchronized WatcherAdminAgent getInstance() {
		if(instance == null) {
			instance = new WatcherAdminAgent();
		}
		return instance;
	}

	@Override
	protected void setup() {
		// Printout a hello message
		logger.log(Level.INFO, "WatcherAdmin-agent " + getAID().getName() + " starting.");

		//Register behaviours
		this.addBehaviour(new AdminBehaviour());

		try {
			// Register the agent service in the yellow pages
			LocalJade.registerAgent(this, getAID(), "watcherAdmin");
			logger.log(Level.DEBUG, "WatcherAgent-agent " + getAID().getName() + " registering in DFService.");
		} catch (FIPAException ex) {
			logger.log(Level.ERROR, null, ex);
		}
	}

	@Override
	protected void takeDown() {
		try {
			DFService.deregister(this);
		} catch(FIPAException ex) {
			logger.log(Level.ERROR, null, ex);
		}

		// Printout a dismissal message
		logger.log(Level.INFO, "WatcherAdmin-agent " + getAID().getName() + " terminating.");
	}
}
